package com.wanjia.estate.constant;

import lombok.AllArgsConstructor;

import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Stream;

@AllArgsConstructor
public enum OcrType {

    /**
     * 合同第一页
     */
    HT_01(DocumentType.CONTRACT, "ht01"),
    /**
     * 首次登记证明
     */
    SCDJZM(DocumentType.REGISTRATION_CERTIFICATE, "scdjzm"),
    /**
     * 购房发票
     */
    GFFP(DocumentType.INVOICE, "gffp"),

    /**
     * 补充协议
     */
    BCXY(DocumentType.SUPPLEMENTAL, "bcxy"),
    /**
     * 委托授权书
     */
    WTSQS(DocumentType.CONSIGNMENT, "wtsqs"),
    /**
     * 身份证
     */
    SFZ(DocumentType.ID_CARD_IDENTIFICATION, "sfz", "sfzzm", "sfzbm"),
    /**
     * 结婚证
     */
    JHZ(DocumentType.JHZ, "jhz"),
    /**
     * 户口簿
     */
    HKB(DocumentType.HKB, "hkb");


    private final String[] key;
    private final DocumentType type;

    OcrType(DocumentType type, String... key) {
        this.type = type;
        this.key = key;
    }

    public String[] key() {
        return key;
    }

    public DocumentType type() {
        return type;
    }

    public static OcrType get(String key) {
        return Stream.of(values())
                .filter(t -> Arrays.stream(t.key).anyMatch(k -> Objects.equals(k, key)))
                .findFirst()
                .orElse(null);
    }

    public static OcrType get(DocumentType type) {
        return Stream.of(values())
                .filter(t -> Objects.equals(t.type, type))
                .findFirst()
                .orElse(null);
    }
}
